package com.gonsin.gnews.mapper;

import com.gonsin.gnews.annotations.bean.ConfigValueBean;
import com.gonsin.gnews.utils.MapMapHandler;
import org.apache.ibatis.annotations.*;

/**
 * 消息模板数据库接口
 */
@Mapper
//@Component
public interface ConfigValueMapper {

    /**
     * 根据条件搜索模板
     */
    @Results(
            id = "ConfigValueBean",
            value = {
                    @Result(property = "configValueKey", column = "config_value_key"),
                    @Result(property = "content", column = "content", typeHandler = MapMapHandler.class),
                    @Result(property = "edificeKey", column = "edifice_key"),
                    @Result(property = "platform", column = "platform"),
            }
    )
    @Select("<script>" +
            "select m.* from gs_news_config as m " +
            "where m.edifice_key = #{edificeKey} and m.platform = #{platform}" +
            "</script>")
    ConfigValueBean getConfig(
            @Param("edificeKey") String edificeKey, @Param("platform") String platform);


    @Insert("<script>" +
            "insert into gs_news_config set " +
            "   config_value_key = #{bean.configValueKey}," +
            "   edifice_key = #{bean.edificeKey}," +
            "   platform = #{bean.platform}," +
            "   content = #{bean.content, typeHandler=com.gonsin.gnews.utils.MapMapHandler } " +
            "</script>")
    void insertConfig(@Param("bean") ConfigValueBean bean);


    @Insert("<script>" +
            "update gs_news_config set " +
            "   content = #{bean.content, typeHandler=com.gonsin.gnews.utils.MapMapHandler } " +
            "where edifice_key = #{bean.edificeKey} and platform = #{bean.platform}" +
            "</script>")
    void updateConfig(@Param("bean") ConfigValueBean bean);

}
